package basic.sort.tree;

/**
 * @author distantstar
 * @version 1.0
 * @date 2021
 * @description basic.sort.tree
 * @since JDK1.8
 */
public class BasicErgodicRecursion {

    private static class Node {
        public int value;
        public Node left;
        public Node right;

        public Node(int v) {
            value = v;
        }
    }

    private static void pre(Node node) {
        if (node == null) {
            return;
        }

        System.out.print(node.value + " ");
        pre(node.left);
        pre(node.right);
    }

    private static void med(Node node) {
        if (node == null) {
            return;
        }

        med(node.left);
        System.out.print(node.value + " ");
        med(node.right);
    }

    private static void pos(Node node) {
        if (node == null) {
            return;
        }

        pos(node.left);
        pos(node.right);
        System.out.print(node.value + " ");
    }

    public static void main(String[] args) {
        Node head = new Node(1);
        head.left = new Node(2);
        head.right = new Node(3);
        head.left.left = new Node(4);
        head.left.right = new Node(5);
        head.right.left = new Node(6);
        head.right.right = new Node(7);

        pre(head);
        System.out.println("\n========");
        med(head);
        System.out.println("\n========");
        pos(head);
    }
}
